package com.mutual.reins.danger.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mutual.reins.danger.entity.PrptDangerTot;
import com.mutual.reins.danger.mapper.PrptDangerTotMapper;
import com.mutual.reins.danger.service.IPrptDangerTotService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author CodeGenerate
 * @since 2021-03-31
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PrptDangerTotServiceImpl extends ServiceImpl<PrptDangerTotMapper, PrptDangerTot> implements IPrptDangerTotService {

    /**
     * 获取该对象Map（key：投保单号—危险单位号 value：List<PrptDangerTot>）
     *
     * @param queryWrapper 查询条件
     * @return 获取该对象Map
     */
    @Override
    public Map<String, List<PrptDangerTot>> selectPrptDangerTotMap(QueryWrapper queryWrapper) {
        List<PrptDangerTot> prptDangerTotList = this.list(queryWrapper);
        Map<String,List<PrptDangerTot>> prptDangerTotMap = new HashMap<>(16);
        if(ObjectUtil.isNotNull(prptDangerTotList) && !prptDangerTotList.isEmpty()){
            for(PrptDangerTot prptDangerTot:prptDangerTotList){
                if(prptDangerTotMap.containsKey(prptDangerTot.getProposalNo()+"-"+prptDangerTot.getDangerNo())){
                    List<PrptDangerTot> prptDangerTotMapList = prptDangerTotMap.get(prptDangerTot.getProposalNo()+"-"+prptDangerTot.getDangerNo());
                    prptDangerTotMapList.add(prptDangerTot);
                }else{
                    List<PrptDangerTot> prptDangerTotMapList = new ArrayList<>();
                    prptDangerTotMapList.add(prptDangerTot);
                    prptDangerTotMap.put(prptDangerTot.getProposalNo()+"-"+prptDangerTot.getDangerNo(),prptDangerTotMapList);
                }
            }
        }
        return prptDangerTotMap;
    }
}
